package com.weixin.lambda;

import org.junit.Test;

import java.util.Comparator;

/**
 * @ClassName lambda
 * @Description lambda实例
 * @date 2022/2/21 14:39
 * @author: wx
 * @Version 1.0
 */
public class lambda {

    @Test
    public void test() {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("i love tam");
            }
        };
        runnable.run();

        //使用lambda重写的方式
        Runnable runnable1 = () -> System.out.println("i love you");
        runnable1.run();
    }

    @Test
    public void test2() {
        Comparator<Integer> com = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };
        System.out.println(com.compare(1, 12));

        //方法引用
        Comparator<Integer> comparator = Integer::compare;
        System.out.println(comparator.compare(2,4));
    }
}
